package ysjsonrpc

var (
	parseError         = NewJsonRPCError(-32700, "Parse error")
	methodNotFound     = NewJsonRPCError(-32601, "Method not found")
	InvalidParamsError = NewJsonRPCError(-32700, "Invalid params")
)

type JsonRPCError struct {
	Code    int         `json:"code,omitempty"`
	Message string      `json:"message,omitempty"`
	Data    interface{} `json:"data,omitempty"`
}

func NewJsonRPCError(code int, message string, data ...interface{}) *JsonRPCError {
	err := &JsonRPCError{
		Code:    code,
		Message: message,
	}
	if len(data) != 0 {
		err.Data = data[0]
	}
	return err
}
